// import { homestay_detail_api } from './../api/homestay_api.js'
import thumbnail from './../components/overview/index.js'
import './header.js'
import { baseURL } from './../utils/http.js'
let homestay_id = ''
let homestay_detail = {}
let start_date = ''
let end_date = ''

function main(params) {

    get_homestay_detail()
    jump_booking_page()
}
main()
//获取民宿id
function get_homestay_detail(params) {
    homestay_detail=JSON.parse(sessionStorage.getItem('homestay_detail'))
    console.log('homestay_detail',homestay_detail);
    init_render_detail()
}
//初始化渲染详情页
function init_render_detail(params) {
    $('.smallPic img').attr('src',baseURL+homestay_detail.image)
    $('.bigPic img').attr('src',baseURL+homestay_detail.image)
    $('.homestay_title').text(homestay_detail.name)
    $('.homestay_price .price').text(homestay_detail.price)
    //富文本渲染
    $('.description_content').html(homestay_detail.desc)
    $('.facility_content').html(homestay_detail.equipment)
}
//请求民宿详情
function homestay_detail_req(params) {
    homestay_detail_api({ homestay_id }).then(res => {
        homestay_detail = res.data
        thumbnail(homestay_detail)
    })
}
//绑定跳转预定订单页面
function jump_booking_page(params) {
    $('.booking_wrap button').on('click', function () {
        start_date = $('.start_date').val()
        end_date = $('.end_date').val()
        if (localStorage.getItem('token')) {
            if (start_date && end_date) {
                location.assign(`/index/Index/booking_order.html?homestay_id=${homestay_detail.id}&start_date=${start_date}&end_date=${end_date}`)
            } else {
                window.alert('请选择入住日期和退房日期')
            }
        }else{
            window.alert('请登录')
        }
        
    })

}


